<?php
 if(!isset($sp))	
  	$sp=explode("/",$_SERVER['PHP_SELF']);

  if($_SERVER['HTTP_HOST'] == "localhost" || $_SERVER['HTTP_HOST'] == "192.168.1.34")
   {
	  $sp[1] = '/' . $sp[1];
   }
  else
	  $sp[1] = '';
  
  $w_root = $_SERVER['SERVER_NAME'] . $sp[1];
  $w_root = str_replace('//','/',$w_root);
  $w_root = str_replace('\\\\','\\',$w_root);
  
  $s_root = $_SERVER['DOCUMENT_ROOT'] . $sp[1];
  $s_root = str_replace('//','/',$s_root);
  $s_root = str_replace('\\\\','\\',$s_root); 
/*========End Setting up web root and server root =============*/
  require_once $s_root.'/libraryfiles/config.php'; 

//if not login 
if(empty($_SESSION['username']))
{
    ?>
    <script type="text/javascript">
        window.location = "<?php echo W_ROOT;?>/login.php?return_url=<?php echo $CURRENT_URL;?>"
    </script>
    <?php
    exit();
}
// end if not login
  
$include = '
<link rel="stylesheet" href="'.W_ROOT.'/css/admin_style.css" />
<script type="text/javascript" src="'.W_ROOT.'/js/action.js"></script>
<script type="text/javascript" src="'.W_ROOT.'/js/common.js"></script>
<script type="text/javascript" src="'.W_ROOT.'/js/jquery.js"></script>
<script type="text/javascript" src="'.W_ROOT.'/libraryfiles/js_global.php"></script>
<style>
label {
	display: inline;
}

.regular-checkbox {
	display: none;
}

.regular-checkbox + label {
	background-color: #fafafa;
	border: 1px solid #eee;
	box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
	padding: 9px;
	border-radius: 3px;
	display: inline-block;
	position: relative;
    margin: 10px 10px 0 0;
}

.regular-checkbox + label:active, .regular-checkbox:checked + label:active {
	box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px 1px 3px rgba(0,0,0,0.1);
}

.regular-checkbox:checked + label {
	background-color: #e9ecee;
	border: 1px solid #adb8c0;
	box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05), inset 15px 10px -12px rgba(255,255,255,0.1);
	color: #99a1a7;
}

.regular-checkbox:checked + label:after {
	content: "\2718";
    background: none repeat scroll 0 0 #CCCCCC;
    color: #FF0000;
    font-size: 14px;
    left: 0;
    padding: -3px 0 0 0;
    padding-left: 5px;
    position: absolute;
    top: 0;
    width: 19px;
}
</style>	
';	
$view = isset($_GET['view'])?$_GET['view']:'';
switch($view){
 case 'delete':
 if(isset($_GET['view'])&& $_GET['view']=="delete")
     {
      $ids=$_GET['id'];
     
     
      $selec_delet="SELECT *FROM tblproduct AS pro INNER JOIN tblimage AS im ON pro.id=im.product_id WHERE product_id IN($ids)";
      $run_query=mysql_query($selec_delet);
     
      if(mysql_num_rows($run_query)>0)
          {
          while($rows=mysql_fetch_array($run_query))
            {
                $product_image=$rows['images'];
        		$product_thumbnail=$rows['thumbnail'];
        		$product_original_img=$rows['original_img'];
                    unlink("uploads/{$product_image}");
                    unlink("uploads/{$product_thumbnail}");
					unlink("uploads/{$product_original_img}");
        	 }
          }
      $delete_product="DELETE FROM tblproduct WHERE id='".$ids."'"; 
      $del_img = mysql_query("DELETE FROM tblimage WHERE tblimage.`product_id` IN ($ids)");       
      $delete_if=mysql_query($delete_product);         
          if($delete_if)
          {
            header('Location: ' . $_SESSION['shop_return_url']);
          }
        
     }
     
     
	case 'add':
	if(isset($_GET['id'])){
				$id=(int)$_GET['id'];			
			}
			else if(isset($_POST['id'])){
				$id=$_POST['id'][0];
			}
			else $id = 0;
			
	$content = 'add.php';
	break;
	   
	case 'edit':
	if(isset($_GET['id'])){	   
				$id=(int)$_GET['id'];                		
			}
			else if(isset($_POST['id'])){
				$id=$_POST['id'][0];
			}
			else $id = 0;
	$content = 'add.php';
	break;	
	
	case 'addexist':
	if(isset($_GET['id'])){
				$id=(int)$_GET['id'];			
			}
			else if(isset($_POST['id'])){
				$id=$_POST['id'][0];
			}
			else $id = 0;
			
	$content = 'formaddexist.php';
	break;	
	
	case 'editexist':
	if(isset($_GET['id'])){
				$id=(int)$_GET['id'];			
			}
			else if(isset($_POST['id'])){
				$id=$_POST['id'][0];
			}
			else $id = 0;
			
	$content = 'formeditexist.php';
	break;		
	
	case 'publish':
	if (isset($_GET['id']) && (int)$_GET['id'] > 0) {
			$id = (int)$_GET['id'];
		} else {
			header('Location: index.php');
			exit();
		}
		
		if(isset($_GET['pharm_id']) && (int)$_GET['pharm_id']>=0){
			$phar_id = (int)$_GET['pharm_id'];
		}
		
		if(isset($_GET['publish']) && (int)$_GET['publish']>=0 && (int)$_GET['publish']<=1){
			$publish = (int)$_GET['publish'];

		}
		 else {
			header('Location: index.php');
			exit();
		}
		
		//Statement to publish/unpublish User
		publishPro('tblproduct_in_pharmacy',$publish,$id,$phar_id);
		
		header("Location: index.php?".getAllGetParams(array('view','id','publish')));//page=".$page."&");
		exit();
	break;
	
	default:
	$content = 'list.php';	
	break;
}
//require_once TMP_ADMIN_PATH;	
require_once TMP_SELL_ADMIN_PATH;
?>
